//
//  CZMainViewController.swift
//  1215微博终极项目
//
//  Created by chok崋 on 15/12/15.
//  Copyright © 2015年 周卓华. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = CZMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        //首页
        let homeView = CZHomeViewController()
        addChildVC("首页", icon: "tabbar_home", controller: homeView)
        
        //消息
        let messageView = CZMessageViewController()
        addChildVC("消息", icon: "tabbar_message_center", controller: messageView)
        
        //发现
        let discoverView = CZDiscoverViewController()
        addChildVC("发现", icon: "tabbar_discover", controller: discoverView)
        
        //我 
        let profileView = CZProfileViewController()
        addChildVC("我", icon: "tabbar_profile", controller: profileView)
        
    }

    //添加子控制器
    func addChildVC(title:String,icon:String,controller:UITableViewController)->Void
    {
        
        controller.title = title
        controller.tabBarItem.image = UIImage(named: icon)
        let navHome = UINavigationController(rootViewController: controller)
        //设置高亮图片
        let highLight = icon + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named: highLight)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        self.addChildViewController(navHome)
    }
    
}

